/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aptech.campaign.entities;

import com.aptech.campaign.component.PropertyIndex;
import java.sql.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author Tai Nguyen
 */
public class Account implements PropertyIndex {

    private String userName;
    private String password;
    private String fullName;
    private Date birthday;
    private String fone;
    private String gender;
    private String lastError;

    /**
     * @return the userName
     */
    public String getUserName() {
        return userName;
    }

    /**
     * @param userName the userName to set
     */
    public void setUserName(String userName) {
        this.userName = userName;
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * @return the fullName
     */
    public String getFullName() {
        return fullName;
    }

    /**
     * @param fullName the fullName to set
     */
    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    /**
     * @return the birthday
     */
    public Date getBirthday() {
        return birthday;
    }

    /**
     * @param birthday the birthday to set
     */
    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    /**
     * @return the fone
     */
    public String getFone() {
        return fone;
    }

    /**
     * @param fone the fone to set
     */
    public void setFone(String fone) {
        this.fone = fone;
    }

    /**
     * @return the gender
     */
    public String getGender() {
        return gender;
    }

    /**
     * @param gender the gender to set
     */
    public void setGender(String gender) {
        this.gender = gender;
    }

    /**
     * @return the lastError
     */
    public String getLastError() {
        return lastError;
    }

    /**
     * @param lastError the lastError to set
     */
    public void setLastError(String lastError) {
        this.lastError = lastError;
    }
    /*
     * validate data for fields
     */

    public boolean validate() {
        //String parrten
        if (userName.length() < 6) {
            lastError = "userName minimum 6 letter";
            return false;
        }
        if (password.length() < 6) {
            lastError = "password minimum 6 letter";
            return false;
        }
        Pattern pattern = Pattern.compile("[0-9]{6,13}");
        Matcher m = pattern.matcher(fone);
        if (!m.matches()) {
            setLastError("Phone number must has 6-13 number!");
            return false;
        }
        return true;
    }

    public Object getPropertyValue(int index) {
        String value = "";
        switch (index) {
            case 1:
                value = this.getUserName();
                break;
            case 2:
                value = this.getPassword();
                break;
            case 3:
                value = this.getFullName();
                break;
            case 4:
                value = this.getBirthday().toString();
                break;
            case 5:
                value = this.getFone();
                break;
            case 6:
                value = this.getGender();
                break;

        }
        return value;
    }

    public void setPropertyValue(int index, Object value) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Class getPropertyClass(int index) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
